package com.hp.easyBuy.controller;

import com.hp.easyBuy.utils.QiniuUtils;
import com.hp.easyBuy.utils.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.io.InputStream;

@RestController
@RequestMapping("file")
public class FileController {

    @PostMapping("upload")
    //用七牛云工具类上传图片到七牛云
    public R upload(MultipartFile file){
        try {
            InputStream is = file.getInputStream();
            String filename = file.getOriginalFilename();
            R r = QiniuUtils.upload(is, filename);
            return r;
        } catch (IOException e) {
            e.printStackTrace();
            return R.error();
        }
    }
}
